package com.crazymaker.springcloud.base.service;

import com.crazymaker.springcloud.base.dao.SysUserDao;
import com.crazymaker.springcloud.base.dao.UserDao;
import com.crazymaker.springcloud.base.entity.SysUser;
import com.crazymaker.springcloud.base.entity.User;
import com.crazymaker.springcloud.common.dto.UserDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Slf4j
public class UserServiceImpl {

    private UserDao userDao;

    private SysUserDao sysUserDao;

    public UserServiceImpl(UserDao userDao, SysUserDao sysUserDao) {
        this.userDao = userDao;
        this.sysUserDao = sysUserDao;
    }

    /**
     * 加载前端用户
     * @param userId
     * @return
     */
    public UserDTO loadFrontEndUser(Long userId) {
        User user = userDao.selectById(userId);
        if (user != null) {
            UserDTO userDTO = new UserDTO();
            BeanUtils.copyProperties(user, userDTO);
            return userDTO;
        }
        return null;
    }

    /**
     * 加载后端用户
     * @param userId
     * @return
     */
    public UserDTO loadBackEndUser(Long userId) {
        SysUser sysUser = sysUserDao.selectById(userId);
        if (sysUser != null) {
            UserDTO userDTO = new UserDTO();
            BeanUtils.copyProperties(sysUser, userDTO);
            return userDTO;
        }
        return null;
    }

}
